#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,map<string,int> > mp;
int main(){
	int n,d;
	string s1,s2;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s1 >> s2 >> d;
		mp[s2][s1]+=d;
	}
	for(map<string,map<string,int> >::iterator it1=mp.begin();it1!=mp.end();it1++){
		cout << it1->first << endl;
		for(map<string,int>::iterator it2=(it1->second).begin();it2!=(it1->second).end();it2++){
			cout << "   |----" << it2->first << "(" << it2->second << ")" << endl;
		}
	}
	return 0;
}
